-
Notifications
You must be signed in to change notification settings - Fork 917
CSS modules #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS modules #331
Conversation
|
I think searching for static replacement in templates is inconsistent:
I think this can be quite confusing. Instead, I would:
|
|
To me it's much more important to have a simple mindset when using scoped CSS. |
|
That's right. I will remove class replacement in |
Add CSS modules supportSimply use CSS Modules with
Example: <style module="style">
.red { color: red; }
/*
becomes
._8x_KsHmyrocTNd7akA_LL { color: red; }
*/
</style>
<script>
export default {
ready() {
console.log(this.style.red)
// => _8x_KsHmyrocTNd7akA_LL
}
}
</script>
<template>
<h2 v-bind:class="style.red"></h2>
</template> |
|
Use <style scoped lang="stylus" module="style">
.red
color: red
</style> |
36be37b to
da61470
Compare
76e83ee to
773b0c6
Compare
|
Do we need this actually? If you need import classes from '/path/to/style'
export default {
data() {
classes
}
}Then, we could use So, on my opinion, this pr is unnecessary. |
|
|
@YiSiWang I think there is no need to use |
|
@speedornothing |
|
@YiSiWang why do we need to explicitly declare the injected variable name? Using a reserved key like How about something like |
|
@yyx990803 There might be multiple Though I don't think multiple moduled |
|
@YiSiWang I think we can default to |
|
Great idea! I will work on it. But, when use multiple no-module-value |
|
@YiSiWang yeah, throwing an error in that case sounds fine. |
README.md
Outdated
| @@ -1,3 +1,36 @@ | |||
| # Add CSS modules support | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this down to a sub-section instead of at the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course. It's just for reviewers to checkout the new API quickly.
Seems you are satisfied with current API, I will move them to the doc.
440753b to
caf9fd4
Compare
caf9fd4 to
b9fb1c8
Compare
|
@yyx990803 Docs updated. |
|
Thanks for the great work! Btw, would you be interested in porting this to v9.x? (next branch) |
|
@yyx990803 Yes, I'm willing to do it. Thanks for merging and HAPPY MOON FESTIVAL! |
Problems in scoped CSS:
CSS modules can solve these problems and is compatible with
scoped.Add CSS modules support
Basic
Simply use CSS modules with
<style module="moduleName">andclass="moduleName.className"becomes:
Class names are unique. So your style won't affect any other component.
Tips:
module, animation names are also converted. Feel free to write short class & animation names!module+scoped, you can limit your style to your component more strictly.moduleonly, you can style<slot>in your component.Binding classes
Static class names in binding expression are converted, too.
becomes:
Note: Here, "static class name" means class name in single quotes.
Complex ones (eg.
'a' + 'b') are not supported (and not recommend in Vue).Getting local class name in script
In some cases, you will like to control your class name in script.
You can do it like this: